<extend name="Base:base" />
<block name="base_main">
	<style>
		body{ background:#fff }
		.jiage_table_data{ width:450px;}
		.jiage_table_data td{ height:60px; background:#efefef; width:200px; } 
		.jiage_table_data .bt_j{ width:100px; font-size:12px; text-align:right;}
		.jiage_table_data span.Validform_wrong{ float:left}
		.jiage_table_data td label{ font-weight:100; font-size:14px;}
	</style>
	<div class="tpl-block ">
		<div class="am-g tpl-amazeui-form">
			<div class="am-u-sm-12 am-u-md-11">
				<form class="am-form am-form-horizontal" request_type="parent" action="" ignoreHidden="ignoreHidden" name="myfromSubmit" fun_call="call_fun_check" method="post">
					<div class="am-form-group">
							<label for="user-email" class="am-u-sm-3 am-form-label">锁货付款方式</label>
							<div class="am-u-sm-8 float_left">
								<table class="jiage_table_data">
									<tr>
										<td class="bt_j" valign="middle">类型&nbsp;&nbsp;&nbsp;</td>
										<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" value="1" <?php if( $data['lock_pay_type'] == 1 ) { echo "checked"; } ?> name="distribution[lock_pay_type]" id="pay_type_s"/> 一次付款</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" <?php if( $data['lock_pay_type'] == 2 ) { echo "checked"; } ?> value="2" name="distribution[lock_pay_type]" id="pay_type_s"/> 两次付款</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" value="3" name="distribution[lock_pay_type]" <?php if( $data['lock_pay_type'] == 3 ) { echo "checked"; } ?> id="pay_type_s"/> 三次付款</label></td>
									</tr>
									<tr style="display:<?php echo $data['lock_pay_type'] >= 3 ? "" : 'none'; ?>;">
										<td class="bt_j" valign="middle">收货支付&nbsp;&nbsp;&nbsp;</td>
										<td colspan="3"><input type="text" name="distribution[lock_pay_rule][received]" value="{$data.lock_pay_rule.received}" maxlength="2" id="lock_received" style="width:100px;" datatype="/^[0-9]+$/" nullmsg="收货支付比例不能为空" errormsg="格式错误"  value="" ></td>
									</tr>
									<tr style="display:<?php echo $data['lock_pay_type'] >= 2 ? "" : 'none'; ?>">
										<td class="bt_j" valign="middle">锁货支付&nbsp;&nbsp;&nbsp;</td>
										<td><input type="text" name="distribution[lock_pay_rule][lock]" maxlength="2" value="{$data.lock_pay_rule.lock}" size="10" id="lock_lock" style="width:100px;" datatype="/^[0-9]+$/" nullmsg="锁货支付比例不能为空" errormsg="格式错误"  value="" ></td>
										<td class="bt_j" valign="middle">下单支付&nbsp;&nbsp;&nbsp;</td>
										<td><input type="text" name="distribution[lock_pay_rule][down]" size="10" value="{$data.lock_pay_rule.down}" maxlength="2" id="lock_down" style="width:100px;" datatype="/^[0-9]+$/" nullmsg="下单支付比例不能为空" errormsg="格式错误"  value="" ></td>
									</tr>
								</table>
							</div>
					</div>
					<div class="am-form-group">
							<label for="user-email" class="am-u-sm-3 am-form-label">批发/代发付款方式</label>
							<div class="am-u-sm-8 float_left">
								<table class="jiage_table_data">
									<tr>
										<td class="bt_j" valign="middle">类型&nbsp;&nbsp;&nbsp;</td>
										<td colspan="3">&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" <?php if( $data['wholesale_pay_type'] == 1 ) { echo "checked"; } ?> value="1" name="distribution[wholesale_pay_type]" id="pay_type_s"/> 一次付款</label>&nbsp;&nbsp;&nbsp;&nbsp;<label><input type="radio" value="2" name="distribution[wholesale_pay_type]" <?php if( $data['wholesale_pay_type'] == 2 ) { echo "checked"; } ?> id="pay_type_s"/> 两次付款</label></td>
									</tr>
									<tr style="display:none;"></tr>
									<tr style="display:<?php echo $data['wholesale_pay_type'] >= 2 ? "" : 'none'; ?>;">
										<td class="bt_j" valign="middle">下单支付&nbsp;&nbsp;&nbsp;</td>
										<td><input type="text" name="distribution[wholesale_pay_rule][down]" value="{$data.wholesale_pay_rule.down}" id="wholesale_down" maxlength="2" size="10" style="width:100px;" datatype="/^[0-9]+$/" nullmsg="下单支付比例不能为空" errormsg="格式错误"  value="" ></td>
										<td class="bt_j" valign="middle">收货支付&nbsp;&nbsp;&nbsp;</td>
										<td><input type="text" name="distribution[wholesale_pay_rule][received]" value="{$data.wholesale_pay_rule.received}" id="wholesale_received" maxlength="2" style="width:100px;" datatype="/^[0-9]+$/" nullmsg="收货支付比例不能为空" errormsg="格式错误"  value="" ></td>
									</tr>
								</table>
							</div>
					</div>
					<div class="am-form-group">
						<div class="am-u-sm-9 am-u-sm-push-3">
							<input type="hidden" value="{$data.id}" name="distribution[id]" /> 
							<button type="submit" class="am-btn am-btn-primary">确认修改</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<script>
		$('input#pay_type_s').click(function(){
			var _self = $(this).closest('tr');
			if( $(this).val() == 2 ) {
					_self.next().next().show();
					_self.next().hide();
			} else if( $(this).val() == 3 ) {
					_self.next().show();
					_self.next().next().show();
			} else {
					_self.next().hide();
					_self.next().next().hide();
			}
		});
		
		function call_fun_check() {
			var lock_down = $('#lock_down').val();
			var lock_lock = $('#lock_lock').val();
			var lock_received = $('#lock_received').val();
			var wholesale_down = $('#wholesale_down').val();
			var wholesale_received = $('#wholesale_received').val();
			if( $('input[name="distribution[lock_pay_type]"]:checked').val() == '2' ) {
				if( parseInt( lock_down ) + parseInt( lock_lock ) != 100 ) {
					error('锁货支付比例总和必须为100！');
					return false;
				}
			} else if( $('input[name="distribution[lock_pay_type]"]:checked').val() == '3' ) {
				if( parseInt( lock_down ) + parseInt( lock_received ) + parseInt( lock_lock ) != 100 ) {
					error('锁货支付比例总和必须为100！');
					return false;
				}
			}
			if( $('input[name="distribution[wholesale_pay_type]"]:checked').val() == '2' ) {
				if( parseInt( wholesale_down ) + parseInt( wholesale_received ) != 100 ) {
					error('批发/代发支付比例总和必须为100！');
					return false;
				}
			}
		}
		call_submit_back_flag = true;
		function call_submit_back_func( data ) {
			parent.location.reload();
		}
	</script>
</block>